﻿<%@ Application Language="C#" %>
<%@ Import Namespace="EuphoricNation.Rewrite" %>
<%@ Import Namespace="EuphoricNation.Util" %>

<script runat="server">

    private readonly string[] WHITELIST_FILES = { "google01817224bd2c74e7.html" };
    
    void Application_Start(object sender, EventArgs e) 
    {
        RegisterRoutes();
        RegisterRedirects();
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Application_BeginRequest(object sender, EventArgs e)
    {
        string server = Request.ServerVariables["SERVER_NAME"].ToLower();

        // Force domain names
        if (server != "localhost")
        {
            foreach (string item in WHITELIST_FILES)
            {
                if (Request.Path.Contains(item.ToLower()))
                    return;
            }

            if ((server.Contains("euphoricnation.co.uk") && server != "www.euphoricnation.co.uk") || server == "euphoricnation.com")
                Useful.RedirectPermanent("http://www.euphoricnation.com" + Request.RawUrl);
        }
    }

    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        switch (custom)
        {
            case "path":
                return context.Request.Url.Host + "_" + context.Request.RawUrl;
        }

        // We can't handle this - fall back to .NET
        return base.GetVaryByCustomString(context, custom);
    }

    public void RegisterRoutes()
    {
        // Informational
        Routes.Current.AddRoute(new Route("/FAQ/", "~/templates/Information/FAQ.aspx"));
        Routes.Current.AddRoute(new Route("/About/", "~/templates/Information/About.aspx"));
        Routes.Current.AddRoute(new Route("/Links/", "~/templates/Information/Links.aspx"));
        
        // Contact & Request
        Routes.Current.AddRoute(new Route("/Contact/", "~/templates/Contact/Contact.aspx"));
        
        // Searching
        Routes.Current.AddRoute(new Route("/Search/", "~/templates/Search/Search.aspx"));
        Routes.Current.AddRoute(new Route("/Search/q/{query}/", "~/templates/Search/SearchResults.aspx"));

        // Accounts
        Routes.Current.AddRoute(new Route("/Profile/", "~/templates/Accounts/MyAccount.aspx"));
        Routes.Current.AddRoute(new Route("/Login/", "~/templates/Accounts/Login.aspx"));
        Routes.Current.AddRoute(new Route("/Forgot/", "~/templates/Accounts/Forgot.aspx"));
        Routes.Current.AddRoute(new Route("/Register/", "~/templates/Accounts/Register.aspx"));
        Routes.Current.AddRoute(new Route("/Accounts/", "~/templates/Accounts/AccountsList.aspx"));
        Routes.Current.AddRoute(new Route("/Accounts/{name}/", "~/templates/Accounts/ViewAccount.aspx"));
        
        // Tutorials
        
        // Games
        
        // Websites
        
        // Applications
        
        // Blog
        
        //Routes.Current.AddRoute(new Route("", "~/templates/"));
    }

    public void RegisterRedirects()
    {
        //
    }
    
    
       
</script>
